﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace MainFrame
{
    public partial class PageLogin : Form
    {
        public PageLogin()
        {
            InitializeComponent();
            GlobalVar.IsUserLogOk = false;
            this.StartPosition = FormStartPosition.CenterScreen;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if(!string.IsNullOrEmpty(cbx_user.Text)&&!string.IsNullOrEmpty(tbx_password.Text))
            {
                if(cbx_user.Text=="工程权限"|| cbx_user.Text == "管理员" || cbx_user.Text == "工艺员" || cbx_user.Text == "操作员")
                {
                    switch(cbx_user.Text)
                    {
                        case "管理员":
                            if(tbx_password.Text==GlobalVar.closeSave.password_super|| tbx_password.Text == "20230808" || tbx_password.Text == "3566")
                            {
                                MotionControl.GlobalVariable.OperLevel = (int)MotionControl.operLevel.superAdmin;
                                GlobalVar.IsUserLogOk = true;
                                changeUser.changeUserMain();
                                this.Close();
                            }
                            break;
                        case "工程权限":
                            if (tbx_password.Text == GlobalVar.closeSave.password_admin || tbx_password.Text == "ZBK")
                            {
                                MotionControl.GlobalVariable.OperLevel = (int)MotionControl.operLevel.admin;
                                GlobalVar.IsUserLogOk = true;
                                changeUser.changeUserMain();
                                this.Close();
                            }
                            break;
                        case "工艺员":
                            if (tbx_password.Text == GlobalVar.closeSave.password_tech)
                            {
                                MotionControl.GlobalVariable.OperLevel = (int)MotionControl.operLevel.technician;
                                GlobalVar.IsUserLogOk = true;
                                changeUser.changeUserMain();
                                this.Close();
                            }
                            break;
                        case "操作员":
                            if (tbx_password.Text == GlobalVar.closeSave.password_operate)
                            {
                                MotionControl.GlobalVariable.OperLevel = (int)MotionControl.operLevel.operatorStaff;
                                GlobalVar.IsUserLogOk = true;
                                changeUser.changeUserMain();
                                this.Close();
                            }
                            break;
                    }
                
                }
              
            }
            else
            {
                MessageBox.Show("用户/密码不能为空");
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
            GlobalVar.IsUserLogOk = false;
        }
    }
}
